import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

export const constantRoutes = [
  { path: '/login', component: () => import('@/views/login') },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard', component: () => import('@/views/dashboard'), name: 'dashboard',
        meta: {
          title: '工作台',
          icon: '工作台'
        }}
    ]
  },
  {
    path: '/garden',
    component: Layout,
    name: 'garden',
    meta: {
      title: '园区管理',
      icon: '园区'
    },
    children: [
      {
        name: 'building',
        path: 'building',
        component: () => import('@/views/building'),
        meta: {
          title: '楼宇管理'
        }
      },
      {
        name: 'enterprise',
        path: 'enterprise',
        component: () => import('@/views/enterprise'),
        meta: {
          title: '企业管理'
        }
      }

    ]
  },
  {
    path: '/mocs',
    component: Layout,
    meta: {
      title: '行车管理',
      icon: '车'
    },
    name: 'mocs',
    children: [
      {
        name: 'district',
        path: 'district',
        component: () => import('@/views/district'),
        meta: {
          title: '区域管理'
        }
      },
      {
        name: 'monthCard',
        path: 'monthCard',
        component: () => import('@/views/monthCard'),
        meta: {
          title: '月卡管理'
        }
      },

      {
        name: 'parkingFee',
        path: 'parkingFee',
        component: () => import('@/views/parkingFee'),
        meta: {
          title: '停车缴费管理'
        }
      },
      {
        name: 'billingRule',
        path: 'billingRule',
        component: () => import('@/views/billingRule'),
        meta: {
          title: '计费规则管理'
        }
      }

    ]
  },
  {
    path: '/condoFee',
    component: Layout,
    children: [{
      path: '',
      name: 'condoFee',
      component: () => import('@/views/condoFee'),
      meta: {
        title: '物业费管理',
        icon: '物业费'
      }
    }]
  },
  {
    path: '/ieceSwing',
    component: Layout,
    name: 'ieceSwing',
    meta: {
      title: '一体杆管理',
      icon: '一体杆'
    },
    children: [
      {
        path: '',
        name: 'ieceSwing',
        component: () => import('@/views/ieceSwing'),
        meta: {
          title: '一体杆管理'

        }
      },
      {
        path: 'alarm',
        name: 'alarm',
        component: () => import('@/views/alarm'),
        meta: {
          title: '告警记录'
        }
        // hidden: true
      }

    ]
  },
  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: {
      title: '系统管理',
      icon: '系统管理'
    },
    children: [
      {
        path: 'employee',
        name: 'employee',
        component: () => import('@/views/employee'),
        meta: {
          title: '员工管理'
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/role'),
        meta: {
          title: '角色管理'
        }
      }

    ]
  },
  {
    name: 'detail',
    path: '/enterprise/detail',
    component: () => import('@/views/enterprise/detail.vue'),
    meta: {
      title: '添加企业'
    },
    hidden: true
  },

  {
    name: 'addPage',
    path: '/monthCard/addPage',
    component: () => import('@/views/monthCard/addPage.vue'),
    meta: {
      title: '添加月卡'
    },
    hidden: true
  },
  {
    name: 'addRenew',
    path: '/monthCard/addRenew',
    component: () => import('@/views/monthCard/addRenew.vue'),
    meta: {
      title: '月卡续费'
    },
    hidden: true
  },
  {
    name: 'addRole',
    path: '/role/addRole',
    component: () => import('@/views/role/addRole.vue'),
    meta: {
      title: '添加角色'
    },
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
